<template>
  <div class="script-card">
    <img :src="image" alt="Script Image" class="script-card-image">
    <div class="script-card-content">
      <div class="script-author">

        <span class="author-name">{{ author }}</span>
        <span class="post-time">{{ upload_time }}</span>
      </div>
      <h3 class="script-title">{{ title }}</h3>
      <p class="script-content">{{ content }}</p>
      <div class="script-card-footer">
        <div class="interaction-icons">
        </div>
        <button class="play-button" @click="playScript">PLAY</button>
      </div>
    </div>
  </div>
</template>

<script>
import {createConversationService} from "@/api/AIChat"

export default {
  name: 'ScriptCard',
  props: {
    image: String,
    author: String,
    upload_time: String,
    title: String,
    content: String,
    tags: String,
    script_id: Number,
    user_id:Number
  },

  methods: {
    async playScript() {
      // 创建存档
      const conversation_id=(await createConversationService(this.user_id, this.script_id)).data
      // console.log(response)
      this.$emit("refresh")
      // 假设你要跳转到某个播放页面，可以使用路由导航

      this.$router.push({
        name: 'AIOChat',
        params: {
          scriptId: this.script_id, // 替换为实际的 scriptId
          conversationId: conversation_id // 替换为实际的 conversationId
        }
      })
    }
  }
}
</script>

<style scoped>
.script-card {
  background-color: #2c2c2e;
  border-radius: 12px;
  overflow: hidden;
  width: 300px;
  margin: 10px;
  display: flex;
  flex-direction: column;
}

.script-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.script-card-content {
  padding: 15px;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}

.script-author {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.author-name {
  font-weight: bold;
  margin-right: 10px;
}

.post-time {
  color: #888;
  font-size: 12px;
}

.script-title {
  font-size: 1.2em;
  margin-bottom: 10px;
}

.script-content {
  font-size: 0.9em;
  color: #bbb;
  margin-bottom: 20px;
}

.script-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.interaction-icons {
  display: flex;
  gap: 10px;
}

.interaction-icons span {
  display: flex;
  align-items: center;
  font-size: 0.9em;
}

.interaction-icons i {
  margin-right: 5px;
}

.play-button {
  background-color: #3b82f6;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 15px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.play-button:hover {
  background-color: #2563eb;
}
</style>
